/*
********************************************************************************
* Copyright (C) 2022, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : memento.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2022-03-04 version v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
                Compile command: make
********************************************************************************
*/

#include <stdio.h>
#include <string.h>
#include "memento.h"

#define MEM_LOGD(fmt, args...) printf("%d Memento D: " fmt, __LINE__, ##args)
#define MEM_LOGE(fmt, args...) printf("%d Memento E: " fmt, __LINE__, ##args)

CMemento::CMemento(void *pInfo, int size)
{
    mpInfo = NULL;

    if (NULL != pInfo) {
        mpInfo = new char * [size];
        memcpy(mpInfo, pInfo, size);
    } else {
        MEM_LOGE("param is NULL!\n");
    }
}

CMemento::~CMemento()
{
    if (NULL != mpInfo) {
        delete (char *)mpInfo;
        mpInfo = NULL;
    }
}

int CMemento::GetInfo(void *info, int size)
{
    if (NULL == info) {
        MEM_LOGE("info is NULL!\n");
        return -1;
    }

    if (NULL == mpInfo) {
        MEM_LOGE("mpInfo is NULL!\n");
        return -1;
    }

    memcpy(info, mpInfo, size);

    return 0;
}